package cz.muni.fi.pb138.bookinfo;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Info extends Activity {
	
	/** Called when the activity is first created. 
	 * 	Shows the general information about selected book.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);		
		setContentView(R.layout.info);
		
		TextView title = (TextView)findViewById(R.id.titlebook);
		title.setText(getIntent().getStringExtra("title"));
		
		TextView author = (TextView)findViewById(R.id.authorbook);
		Bundle data = getIntent().getBundleExtra("authors");
		List<String> bookAuthors = new ArrayList<String>();
		bookAuthors.addAll(data.getStringArrayList("authors"));
		if(bookAuthors != null && bookAuthors.size() > 0) {
			String author2 = "";
			for(int i = 0; i < bookAuthors.size(); i++) {
				author2 += bookAuthors.get(i);
				if(i < bookAuthors.size() - 1) {
					author2 += ", ";
				}
			}
			author.setText(author2);
		} else {
			author.setText("No author found");
		}
		
		TextView rating = (TextView)findViewById(R.id.ratingbook);
		Double rat = getIntent().getDoubleExtra("rating", 0.00);
		
		if(rat != null && rat != 0.00) {
			rating.setText(String.valueOf(rat));
		} else {
			rating.setText("No rating found");
		}
		
		TextView description = (TextView)findViewById(R.id.descriptionbook);
		description.setText(getIntent().getStringExtra("description"));
	}
}
